package com.whiteape.book.receiver;

import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.umeng.analytics.MobclickAgent;
import com.whiteape.book.WaApp;
import com.whiteape.book.core.manager.ReadSettingManager;
import com.whiteape.book.model.dto.AdInfoBean;
import com.whiteape.book.utils.LogUtils;

public class PackageChangedReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        LogUtils.d("on receive, action is " + action);
        if ("android.intent.action.PACKAGE_ADDED".equals(action)) {
//            Uri data = intent.getData();
//            if (data != null) {
//                String pkgName = data.getSchemeSpecificPart();
//                LogUtils.d("新安装应用了:" + pkgName);
//                if (pkgName.equals("com.zy.yjdwb.aligames")) {
//                    MobclickAgent.onEvent(WaApp.getInstance(), "ad_install");
//
//                }
//
//            }
            if (intent.getData() != null) {
                String packageName = intent.getData().getSchemeSpecificPart();
                AdInfoBean adInfoBean = ReadSettingManager.getInstance().getAdInfo();

                LogUtils.d("package added:" + packageName);
                if (packageName != null && adInfoBean != null && packageName.equals(adInfoBean.getPackageName())) {
                    LogUtils.d("ok ,is my ad,report install");
                    MobclickAgent.onEvent(WaApp.getInstance(), "ad_install");

                }
            }
        } else if ("android.intent.action.PACKAGE_REMOVED".equals(action)) {
            String packageName = intent.getDataString();
            LogUtils.d("package removed:" + packageName);
        }
    }
}
